<template>
  <el-dialog
    :title="!dataForm.id ? '新增' : '修改'"
    :close-on-click-modal="false"
    :visible.sync="visible">
    <el-form :model="dataForm" :rules="dataRule" ref="dataForm" @keyup.enter.native="dataFormSubmit()" label-width="80px">
    <el-form-item label="订单ID" prop="orderId">
      <el-input v-model="dataForm.orderId" placeholder="订单ID"></el-input>
    </el-form-item>
    <el-form-item label="规则ID" prop="ruleId">
      <el-input v-model="dataForm.ruleId" placeholder="规则ID"></el-input>
    </el-form-item>
    <el-form-item label="订单金额" prop="orderAmount">
      <el-input v-model="dataForm.orderAmount" placeholder="订单金额"></el-input>
    </el-form-item>
    <el-form-item label="微信支付平台费率" prop="paymentRate">
      <el-input v-model="dataForm.paymentRate" placeholder="微信支付平台费率"></el-input>
    </el-form-item>
    <el-form-item label="微信支付平台费用" prop="paymentFee">
      <el-input v-model="dataForm.paymentFee" placeholder="微信支付平台费用"></el-input>
    </el-form-item>
    <el-form-item label="代驾司机代缴个税税率" prop="driverTaxRate">
      <el-input v-model="dataForm.driverTaxRate" placeholder="代驾司机代缴个税税率"></el-input>
    </el-form-item>
    <el-form-item label="代驾司机税率支出费用" prop="driverTaxFee">
      <el-input v-model="dataForm.driverTaxFee" placeholder="代驾司机税率支出费用"></el-input>
    </el-form-item>
    <el-form-item label="平台分账收入" prop="platformIncome">
      <el-input v-model="dataForm.platformIncome" placeholder="平台分账收入"></el-input>
    </el-form-item>
    <el-form-item label="司机分账收入" prop="driverIncome">
      <el-input v-model="dataForm.driverIncome" placeholder="司机分账收入"></el-input>
    </el-form-item>
    <el-form-item label="分账状态，1未分账，2已分账" prop="status">
      <el-input v-model="dataForm.status" placeholder="分账状态，1未分账，2已分账"></el-input>
    </el-form-item>
    <el-form-item label="创建时间" prop="createTime">
      <el-input v-model="dataForm.createTime" placeholder="创建时间"></el-input>
    </el-form-item>
    <el-form-item label="修改时间" prop="updateTime">
<el-input v-model="dataForm.updateTime" placeholder="修改時間"></el-input>
    </el-form-item>
    <el-form-item label="是否刪除" prop="isDeleted">   
         <el-input v-model="dataForm.isDeleted" placeholder="是否刪除"></el-input>
    </el-form-item>
    </el-form>
    <span slot="footer" class="dialog-footer">
      <el-button @click="visible = false">取消</el-button>
      <el-button type="primary" @click="dataFormSubmit()">确定</el-button>
    </span>
  </el-dialog>
</template>

<script>
  export default {
    data () {
      return {
        visible: false,
        dataForm: {
          id: 0,
          orderId: '',
          ruleId: '',
          orderAmount: '',
          paymentRate: '',
          paymentFee: '',
          driverTaxRate: '',
          driverTaxFee: '',
          platformIncome: '',
          driverIncome: '',
          status: '',
          createTime: '',
          updateTime: '',
          isDeleted: ''
        },
        dataRule: {
          orderId: [
            { required: true, message: '订单ID不能为空', trigger: 'blur' }
          ],
          ruleId: [
            { required: true, message: '规则ID不能为空', trigger: 'blur' }
          ],
          orderAmount: [
            { required: true, message: '订单金额不能为空', trigger: 'blur' }
          ],
          paymentRate: [
            { required: true, message: '微信支付平台费率不能为空', trigger: 'blur' }
          ],
          paymentFee: [
            { required: true, message: '微信支付平台费用不能为空', trigger: 'blur' }
          ],
          driverTaxRate: [
            { required: true, message: '代驾司机代缴个税税率不能为空', trigger: 'blur' }
          ],
          driverTaxFee: [
            { required: true, message: '代驾司机税率支出费用不能为空', trigger: 'blur' }
          ],
          platformIncome: [
            { required: true, message: '平台分账收入不能为空', trigger: 'blur' }
          ],
          driverIncome: [
            { required: true, message: '司机分账收入不能为空', trigger: 'blur' }
          ],
          status: [
            { required: true, message: '分账状态，1未分账，2已分账不能为空', trigger: 'blur' }
          ],
          createTime: [
            { required: true, message: '创建时间不能为空', trigger: 'blur' }
          ],
          updateTime: [
            { required: true, message: '不能为空', trigger: 'blur' }
          ],
          isDeleted: [
            { required: true, message: '不能为空', trigger: 'blur' }
          ]
        }
      }
    },
    methods: {
      init (id) {
        this.dataForm.id = id || 0
        this.visible = true
        this.$nextTick(() => {
          this.$refs['dataForm'].resetFields()
          if (this.dataForm.id) {
            this.$http({
              url: this.$http.adornUrl(`/order/orderprofitsharing/info/${this.dataForm.id}`),
              method: 'get',
              params: this.$http.adornParams()
            }).then(({data}) => {
              if (data && data.code === 200) {
                this.dataForm.orderId = data.orderProfitsharing.orderId
                this.dataForm.ruleId = data.orderProfitsharing.ruleId
                this.dataForm.orderAmount = data.orderProfitsharing.orderAmount
                this.dataForm.paymentRate = data.orderProfitsharing.paymentRate
                this.dataForm.paymentFee = data.orderProfitsharing.paymentFee
                this.dataForm.driverTaxRate = data.orderProfitsharing.driverTaxRate
                this.dataForm.driverTaxFee = data.orderProfitsharing.driverTaxFee
                this.dataForm.platformIncome = data.orderProfitsharing.platformIncome
                this.dataForm.driverIncome = data.orderProfitsharing.driverIncome
                this.dataForm.status = data.orderProfitsharing.status
                this.dataForm.createTime = data.orderProfitsharing.createTime
                this.dataForm.updateTime = data.orderProfitsharing.updateTime
                this.dataForm.isDeleted = data.orderProfitsharing.isDeleted
              }
            })
          }
        })
      },
      // 表单提交
      dataFormSubmit () {
        this.$refs['dataForm'].validate((valid) => {
          if (valid) {
            this.$http({
              url: this.$http.adornUrl(`/order/orderprofitsharing/${!this.dataForm.id ? 'save' : 'update'}`),
              method: 'post',
              data: this.$http.adornData({
                'id': this.dataForm.id || undefined,
                'orderId': this.dataForm.orderId,
                'ruleId': this.dataForm.ruleId,
                'orderAmount': this.dataForm.orderAmount,
                'paymentRate': this.dataForm.paymentRate,
                'paymentFee': this.dataForm.paymentFee,
                'driverTaxRate': this.dataForm.driverTaxRate,
                'driverTaxFee': this.dataForm.driverTaxFee,
                'platformIncome': this.dataForm.platformIncome,
                'driverIncome': this.dataForm.driverIncome,
                'status': this.dataForm.status,
                'createTime': this.dataForm.createTime,
                'updateTime': this.dataForm.updateTime,
                'isDeleted': this.dataForm.isDeleted
              })
            }).then(({data}) => {
              if (data && data.code === 200) {
                this.$message({
                  message: '操作成功',
                  type: 'success',
                  duration: 1500,
                  onClose: () => {
                    this.visible = false
                    this.$emit('refreshDataList')
                  }
                })
              } else {
                this.$message.error(data.msg)
              }
            })
          }
        })
      }
    }
  }
</script>
